package com.smg.community.service;

import cn.org.rapid_framework.page.Page;
import com.smg.community.dao.SmgMemberDao;
import com.smg.community.model.SmgMember;
import com.smg.community.setting.Cache;
import com.smg.community.setting.ProjectSetting;
import com.smg.community.vo.query.SmgMemberQuery;
import java.util.List;
import javacommon.base.BaseManager;
import javacommon.base.EntityDao;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class SmgMemberManager extends BaseManager<SmgMember, Integer>
{
  private SmgMemberDao smgMemberDao;

  public void setSmgMemberDao(SmgMemberDao dao)
  {
    this.smgMemberDao = dao; }

  public EntityDao getEntityDao() {
    return this.smgMemberDao;
  }

  @Transactional(readOnly=true)
  public Page findPage(SmgMemberQuery query) {
    return this.smgMemberDao.findPage(query);
  }

  public SmgMember getByLoginNameAndPassword(String loginName, String password) {
    return this.smgMemberDao.getByLoginNameAndPassword(loginName, password); }

  public void addTopicCount(int memberId) {
    this.smgMemberDao.addTopicCount(memberId); }

  public void addPoint(int type, int point, String detail, SmgMember member, HttpServletRequest request) {
    try {
      this.smgMemberDao.addPoint(type, point, detail, member);
      request.getSession().setAttribute("SESSION_MEMBER_KEY", getById(member.getMemberId()));
    } catch (Exception e) {
      e.printStackTrace(); }
  }

  public void addPoint(int type, int point, String detail, SmgMember member) {
    try {
      this.smgMemberDao.addPoint(type, point, detail, member);
    } catch (Exception e) {
      e.printStackTrace(); }
  }

  public List<SmgMember> getThreeMemberByBehaviorCount() {
    List tempList = this.smgMemberDao.getThreeMemberByBehaviorCount();
    if (tempList.size() < 3) {
      int size = 3 - tempList.size();
      List list = this.smgMemberDao.getTopXMemberList(size);
      tempList.add(list);
    }
    if (Cache.threeMemberList == null)
      Cache.threeMemberList = tempList;

    if (ProjectSetting.USE_CACHE)
      return Cache.threeMemberList;

    return tempList; }

  public List<SmgMember> getFourFriendMember(Integer memberId) {
    return this.smgMemberDao.getFourFriendMember(memberId); }

  public List<SmgMember> getFourStaffMember() {
    return this.smgMemberDao.getFourStaffMember(); }

  public void addVisitCount(int viewMemberId) {
    this.smgMemberDao.addVisitCount(viewMemberId); }

  public List<SmgMember> getFocusMemberByMemberId(Integer memberId, int size) {
    return this.smgMemberDao.getFocusMemberByMemberId(memberId, size); }

  public void updateHead(Integer memberId, String headImage) {
    this.smgMemberDao.updateHead(memberId, headImage); }

  public SmgMember getByNickname(String nickName) {
    return this.smgMemberDao.getByNickname(nickName); }

  public void updatePassword(Integer memberId, String newpassword) {
    this.smgMemberDao.updatePassword(memberId, newpassword); }

  public List<SmgMember> getFourLastedJoinGroupMember(Integer groupId) {
    return this.smgMemberDao.getFourLastedJoinGroupMember(groupId); }

  public SmgMember getStarMemberInOneWeek() {
    return this.smgMemberDao.getStarMemberInOneWeek(); }

  public void addFocusAndFansCount(int fromMemberId, int focusMemberId) {
    this.smgMemberDao.addFocusAndFansCount(fromMemberId, focusMemberId); }

  public void subFocusAndFansCount(Integer fromMemberId, int focusMemberId) {
    this.smgMemberDao.subFocusAndFansCount(fromMemberId, focusMemberId); }

  public void subPoint(Integer memberId, int point) {
    this.smgMemberDao.subPoint(memberId, point); }

  public SmgMember getByLoginName(String loginName) {
    return this.smgMemberDao.getByLoginName(loginName); }

  public void updateNickname(Integer memberId, String nickName) {
    this.smgMemberDao.updateNickname(memberId, nickName); }

  public SmgMember getRandomMember() {
    return this.smgMemberDao.getRandomMember(); }

  public void updateNicknameFirstchar(Integer memberId, String nickNameFirstchar) {
    this.smgMemberDao.updateNicknameFirstchar(memberId, nickNameFirstchar);
  }
}